/**
 * @brief RUDP 服务器端客户端对
 * @version 1.0
 * @date 2018-4-9
 * @author 宋炜
*/

#ifndef __RUDP_LINK_HPP__
#define __RUDP_LINK_HPP__
#include "misc.h"
class rudpServer;

class rudpLink
{
public:
	enum  err_code
	{
		ERR_BASE,
		ERR_SERVER_NULL,
		ERR_PEER_NULL,
		OK = 0
	};
private:
	rudpServer            * p_svr;
	const struct sockaddr * add;  
	hash_t                  m_id;

	std::function< void ( const char * data , size_t l ) >    recv_cb;
	std::function< void () >     send_cb;
	std::function< void () >     close_cb;
	std::function< void ( err_code ) >     error_cb;
public:
	rudpLink( rudpServer * svr , const struct sockaddr * add );
	virtual ~rudpLink();

	size_t send( const char * data , size_t len );
	void close();
	/**
	 * @brief 设置操作响应函数
	*/
	void on_recv( std::function< void ( const char * data , size_t l ) > fun );
	void on_send( std::function< void () >  fun );
	void on_close( std::function< void () > fun );
	void on_error( std::function< void ( err_code ) > );
};
#endif
